From b79008bbf9dcf4482555085a6b1a277ceba3442b Mon Sep 17 00:00:00 2001 From: Martin Nordholts Date: Sun, 16 Nov 2008 12:36:50 +0000 Subject: [PATCH] Add #define BABL_ALPHA_THRESHOLD which is the alpha threshold used in the * babl/babl.h: Add #define BABL_ALPHA_THRESHOLD which is the alpha threshold used in the reference implementation for un-pre-multiplication of color data. * babl/base/model-rgb.c * babl/base/model-gray.c * extensions/gegl-fixups.c: Use the define, a consistent alpha threshold improves accurucy of conversions. svn path=/trunk/; revision=356 --- ChangeLog | 11 +++++++++++ babl/babl.h | 5 +++++ babl/base/model-gray.c | 4 ++-- babl/base/model-rgb.c | 4 ++-- extensions/gegl-fixups.c | 8 ++++---- 5 files changed, 24 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4592d97..6a5c6f5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2008-11-16 Martin Nordholts + + * babl/babl.h: Add #define BABL_ALPHA_THRESHOLD which is the alpha + threshold used in the reference implementation for + un-pre-multiplication of color data. + + * babl/base/model-rgb.c + * babl/base/model-gray.c + * extensions/gegl-fixups.c: Use the define, a consistent alpha + threshold improves accurucy of conversions. + 2008-11-16 Martin Nordholts * extensions/gegl-fixups.c (conv_rgbAF_sdl32) diff --git a/babl/babl.h b/babl/babl.h index 019f96a..71d94c3 100644 --- a/babl/babl.h +++ b/babl/babl.h @@ -45,6 +45,11 @@ typedef struct _BablList BablList; */ #define BABL_MAGIC 0xbAb100 +/* Alpha threshold used in the reference implementation for + * un-pre-multiplication of color data. + */ +#define BABL_ALPHA_THRESHOLD 0.0001 + enum { BABL_INSTANCE = BABL_MAGIC, BABL_TYPE, diff --git a/babl/base/model-gray.c b/babl/base/model-gray.c index b7004d4..13031a0 100644 --- a/babl/base/model-gray.c +++ b/babl/base/model-gray.c @@ -308,7 +308,7 @@ gray_alpha_premultiplied_to_rgba (int src_bands, double luminance = *(double *) src[0]; double alpha = *(double *) src[1]; - if (alpha > 0.00001) + if (alpha > BABL_ALPHA_THRESHOLD) { luminance = luminance / alpha; } @@ -408,7 +408,7 @@ premultiplied_to_non_premultiplied (int src_bands, alpha = *(double *) src[src_bands - 1]; for (band = 0; band < src_bands - 1; band++) { - if (alpha > 0.001) + if (alpha > BABL_ALPHA_THRESHOLD) { *(double *) dst[band] = *(double *) src[band] / alpha; } diff --git a/babl/base/model-rgb.c b/babl/base/model-rgb.c index a1c1c37..dd8d93e 100644 --- a/babl/base/model-rgb.c +++ b/babl/base/model-rgb.c @@ -283,7 +283,7 @@ premultiplied_to_non_premultiplied (int src_bands, alpha = *(double *) src[src_bands - 1]; for (band = 0; band < src_bands - 1; band++) { - if (alpha > 0.001) + if (alpha > BABL_ALPHA_THRESHOLD) { *(double *) dst[band] = *(double *) src[band] / alpha; } @@ -332,7 +332,7 @@ rgba_gamma_2_2_premultiplied2rgba (char *src, while (n--) { double alpha = ((double *) src)[3]; - if (alpha > 0.0001) + if (alpha > BABL_ALPHA_THRESHOLD) { ((double *) dst)[0] = gamma_2_2_to_linear (((double *) src)[0] / alpha); ((double *) dst)[1] = gamma_2_2_to_linear (((double *) src)[1] / alpha); diff --git a/extensions/gegl-fixups.c b/extensions/gegl-fixups.c index 9bc6b8b..48d5f09 100644 --- a/extensions/gegl-fixups.c +++ b/extensions/gegl-fixups.c @@ -337,7 +337,7 @@ conv_rgbAF_sdl32 (unsigned char *srcc, { float ca = src[i]; int ret; - if (alpha < 0.0001) + if (alpha < BABL_ALPHA_THRESHOLD) ret = 0; else ret = table_F_8g[gggl_float_to_index16 (ca / alpha)]; @@ -393,7 +393,7 @@ conv_rgbAF_rgb8 (unsigned char *srcc, while (n--) { float alpha = src[3]; - if (alpha < 0.00001) + if (alpha < BABL_ALPHA_THRESHOLD) { dst[0] = 0; dst[1] = 0; @@ -471,7 +471,7 @@ conv_rgbAF_rgbaF (unsigned char *srcc, { float alpha = src[3]; float recip = 1.0/alpha; - if (alpha < 0.00001) + if (alpha < BABL_ALPHA_THRESHOLD) recip = 0.0; dst[0] = src[0] * recip; dst[1] = src[1] * recip; @@ -498,7 +498,7 @@ conv_rgbAF_lrgba8 (unsigned char *srcc, { float alpha = src[3]; float recip = (1.0/alpha); - if (alpha < 0.00001) + if (alpha < BABL_ALPHA_THRESHOLD) { dst[0] = dst[1] = dst[2] = dst[3] = 0; } -- 2.30.2